function loadAMSServerControlPage(ip) {
	var data = 
	            {title: ip, ip: ip}
	        ;
    console.log(data);
    var html = new EJS({url: 'amsServerControlView.ejs'}).render(data);
    $("#page").html(html);
}

function loadViewContent(ip, command) {
    $.ajax( 'rest/' + ip+'/'+command, {
        dataType:'html',
        data:{},
        type:'GET',
        success:function ( data ) {
            var temp = 
			{title: ip, ip: ip, content: data}
        ;
            var html = new EJS({url: 'amsServerControlView.ejs'}).render(temp);
            $("#page").html(html);
        }
    })
    .error( function() {
        console.log("error");
    });
    
    
}

$( '#page' ).ready( function() {
	$( '#loading' ).hide();
});

$( document ).ready( function() {
	$( '#loading' ).hide();
    $( '#submit' ).click( function( event ) {
        event.preventDefault();
        var result = $( '#result' ),
        ip = $.trim( $( '#ip' ).val() );
        console.log("ip: " + ip);
        //var username = $.trim( $( '#username' ).val());
        //var password = $.trim( $( '#password' ).val());
        
        result.removeClass( 'invalid' );
        if( !ip || !ip.length ) {
            result.addClass( 'invalid' ).text( 'An ip is required!' );
            return;
        }
        console.log("clicked: " + ip);
        $.ajax( 'rest/' + ip+'/status', {
            dataType:'html',
            data:{},
            type:'GET',
            success:function ( data ) {
                console.log("success: " + data);
                $( '#result' ).html(data);
            }
        })
        .error( function() {
            console.log("error");
        });
    });
    
    $.ajax( 'rest/html/getServerList', {
        dataType: 'html',
        data:{},
        type:'GET',
        success:function ( data ) {
            $( '#sidebar_content' ).html(data);
        }
        
    }).error( function() {
        console.log("error");
    });
    
    $('#tree1').tree({
    	  dataUrl: 'rest/json/getServerList',
    	  selectable: true
    	});

    $('#tree1').bind(
    	  'tree.init',
    	  function() {
    	    var node = $tree.tree('getNodeById', 1);
    	    console.log("select Node1");
    	    $tree.tree('selectNode', node, true);
    	  }
    	);
	
    //show loading status
    jQuery.ajaxSetup({
    	  beforeSend: function() {
    	     $('#loading').show();
    	  },
    	  complete: function(){
    	     $('#loading').hide();
    	  },
    	  success: function() {}
    	});
}); // (document).ready